# Makefile for GNU patch.
# Copyright 1993, 1997-1998, 1999 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#### Start of system configuration section. ####

srcdir = @srcdir@
VPATH = @srcdir@

@SET_MAKE@

CC = @CC@
ed_PROGRAM = @ed_PROGRAM@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
transform = @program_transform_name@

CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = @DEFS@
EXEEXT = @EXEEXT@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
PACKAGE = @PACKAGE@
U = @U@
VERSION = @VERSION@

# override Solaris make.rules
.SCCS_GET:
	$(Q)bk get -q $@

prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = $(exec_prefix)/bin

# Where to put the manual pages.
mandir = @mandir@
man1dir = $(mandir)/man1
# Extension (including `.') for the manual page filenames.
man1ext = .1

# Hook for nonstandard builds.
CONFIG_STATUS = config.status

#### End of system configuration section. ####

SHELL = /bin/sh

LIBSRCS = getopt.c getopt1.c malloc.c memchr.c realloc.c rename.c
SRCS = addext.c argmatch.c backupfile.c basename.c error.c inp.c maketime.c \
	mkdir.c partime.c patch.c pch.c quotearg.c quotesys.c \
	rmdir.c util.c version.c xmalloc.c $(LIBSRCS)
OBJS = addext$U.o argmatch$U.o backupfile$U.o basename$U.o error$U.o inp$U.o \
	maketime.o partime.o patch$U.o pch$U.o quotearg$U.o quotesys.o \
	util$U.o version$U.o xmalloc$U.o $(LIBOBJS)
HDRS = argmatch.h backupfile.h basename.h common.h error.h getopt.h \
	inp.h maketime.h partime.h patchlevel.h pch.h quotearg.h quotesys.h \
	util.h version.h xalloc.h
MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README \
	aclocal.m4 ansi2knr.1 ansi2knr.c \
	config.guess config.hin config.sub configure configure.in \
	install-sh mkinstalldirs patch.man
DISTFILES = $(MISC) $(SRCS) $(HDRS)
DISTFILES_M4 = $(ACINCLUDE_INPUTS)
DISTFILES_PC = pc/chdirsaf.c
DISTFILES_PC_DJGPP = pc/djgpp/README pc/djgpp/config.sed \
	pc/djgpp/configure.bat pc/djgpp/configure.sed

patch_name = `echo patch | sed '$(transform)'`

all:: patch$(EXEEXT)

info::
check::
installcheck::

COMPILE = $(Q)$(CC) -c $(CPPFLAGS) $(DEFS) -Ded_PROGRAM=\"$(ed_PROGRAM)\" \
	-I. -I$(srcdir) $(CFLAGS)

.c.o:
	$(if $(Q),@echo CC gnu/patch/$<,)
	$(COMPILE) $<

patch$(EXEEXT): $(OBJS)
	$(if $(Q),@echo LINK gnu/patch/$<,)
	$(Q)$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS)

install:: all installdirs
	$(INSTALL_PROGRAM) patch$(EXEEXT) $(bindir)/$(patch_name)$(EXEEXT)
	-$(INSTALL_DATA) $(srcdir)/patch.man $(man1dir)/$(patch_name)$(man1ext)

installdirs::
	$(SHELL) $(srcdir)/mkinstalldirs $(bindir) $(man1dir)

install-strip::
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

uninstall::
	rm -f $(bindir)/$(patch_name)$(EXEEXT)
	rm -f $(man1dir)/$(patch_name)$(man1ext)

Makefile: Makefile.in $(CONFIG_STATUS)
	$(SHELL) $(CONFIG_STATUS)
config.status: configure
	$(SHELL) $(CONFIG_STATUS) --recheck
configure: configure.in $(srcdir)/aclocal.m4
	cd $(srcdir) && autoconf
config.hin: configure.in
	cd $(srcdir) && rm -f config.hin && autoheader

M4DIR = $(srcdir)/m4
ACINCLUDE_INPUTS = $(M4DIR)/ccstdc.m4 $(M4DIR)/d-ino.m4 \
  $(M4DIR)/inttypes_h.m4 $(M4DIR)/largefile.m4 $(M4DIR)/malloc.m4 \
  $(M4DIR)/protos.m4 $(M4DIR)/realloc.m4 $(M4DIR)/utimbuf.m4

# do not re-gen aclocal.m4, always use the one we checked out from BK
#$(srcdir)/aclocal.m4: $(ACINCLUDE_INPUTS)
#	cat $(ACINCLUDE_INPUTS) >$(srcdir)/aclocal.m4

patchlevel.h: configure.in
	echo '#define PATCH_VERSION "$(VERSION)"' >patchlevel.h

TAGS: $(HDRS) patchlevel.h $(SRCS)
	etags $(HDRS) patchlevel.h $(SRCS)

mostlyclean::
	rm -f ansi2knr core* *core *.o *_.c

clean:: mostlyclean
	rm -f patch$(EXEEXT)

distclean:: clean
	rm -f Makefile config.cache config.log config.status config.h

maintainer-clean::
	@echo "This command is intended for maintainers to use;"
	@echo "rebuilding the deleted files requires special tools."
	$(MAKE) distclean
	rm -f TAGS

PV = $(PACKAGE)-$(VERSION)

dist:: $(DISTFILES) $(DISTFILES_M4) $(DISTFILES_PC) $(DISTFILES_PC_DJGPP)
	rm -rf $(PV)
	mkdir $(PV) $(PV)/m4 $(PV)/pc $(PV)/pc/djgpp
	cp -p $(DISTFILES) $(PV)
	cp -p $(DISTFILES_M4) $(PV)/m4
	cp -p $(DISTFILES_PC) $(PV)/pc
	cp -p $(DISTFILES_PC_DJGPP) $(PV)/pc/djgpp
	tar -chf - $(PV) | gzip -9 >$(PV).tar.gz
	rm -rf $(PV)

ansi2knr.o: config.h
ansi2knr: ansi2knr.o
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) ansi2knr.o $(LIBS)
addext_.c argmatch_.c backupfile_.c basename_.c error_.c \
getopt_.c getopt1_.c inp_.c malloc_.c mkdir_.c patch_.c pch_.c quotearg_.c \
rename_.c util_.c version_.c xmalloc_.c: ansi2knr
.SUFFIXES: _.c
.c_.c:
	./ansi2knr $< $@

$(OBJS): config.h
addext$U.o: backupfile.h
argmatch$U.o: argmatch.h error.h quotearg.h
backupfile$U.o: argmatch.h backupfile.h
error$U.o: error.h
getopt$U.o getopt1$U.o: getopt.h
inp$U.o: backupfile.h common.h inp.h pch.h quotearg.h util.h xalloc.h
maketime.o: maketime.h partime.h
partime.o: partime.h
patch$U.o: argmatch.h backupfile.h common.h getopt.h inp.h \
	pch.h quotearg.h util.h version.h xalloc.h
pch$U.o: backupfile.h basename.h common.h inp.h pch.h quotearg.h util.h
quotearg$U.o: quotearg.h xalloc.h
quotesys.o: quotesys.h
util$U.o: backupfile.h basename.h common.h maketime.h \
	partime.h quotearg.h quotesys.h util.h version.h xalloc.h
version$U.o: common.h patchlevel.h util.h version.h
xmalloc$U.o: xalloc.h
